#define _CRT_SECURE_NO_WARNINGS 1
/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        queue<Node*> qi;
        vector<vector<int>> ret;
        if (root == nullptr) return ret;
        qi.push(root);
        int ce = 0;
        while (qi.size())
        {
            ret.push_back(vector<int>());
            int n = qi.size();
            for (int i = 0; i < n; i++)
            {
                Node* parent = qi.front();
                for (auto child : parent->children) qi.push(child);
                ret[ce].push_back(parent->val);
                qi.pop();
            }
            ce++;
        }
        return ret;
    }
};